<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Plugin ID Generator</title>
<meta http-equiv="content-type" content="text/html; charset=utf-8" />
<meta http-equiv="MSThemeCompatible" content="yes" />
<!--[if IE]>
<hta:application
  scroll="no"
  maximizebutton="no"
/>
<![endif]-->
<script type="text/javascript">//<![CDATA[
//CRC32 implementation copied from Wikipedia
//(http://en.wikipedia.org/wiki/Cyclic_redundancy_check#Example_implementation)
var crc32_table = [];

for (var i = 0; i < 256; ++i) {
  var c = i;
  for (var j = 0; j < 8; ++j)
    c = (c & 1) ? (0xEDB88320 ^ (c >> 1)) : (c >> 1);
  crc32_table.push(c);
}

function crc32(str) {
  var c = 0xFFFFFFFF;
  for (var i = 0; i < str.length; ++i)
    c = crc32_table[(c ^ str.charCodeAt(i)) & 0xFF] ^ (c >> 8);
  return c ^ 0xFFFFFFFF;
}

function numToHex(num) {
  if (num < 0) num += 0xFFFFFFFF;
  var hexStr = num.toString(16).toUpperCase();
  while (hexStr.length < 8)
    hexStr = '0' + hexStr;
  return '0x' + hexStr;
}

window.onload = function () {
  window.resizeTo(600, 300);
  var pluginNameInput = document.getElementById('pluginNameInput');
  var outputBox = document.getElementById('outputbox');

  document.getElementById('btnUseCrc32').onclick = function () {
    outputBox.innerHTML = "//Copy and paste this code to definitions.h<br />"
      + "//Plugin ID generated by MakeID.HTA (based on CRC32)<br />"
      + "#define PLUGIN_ID " + numToHex(crc32(pluginNameInput.value));
  };

  document.getElementById('btnUseRandom').onclick = function () {
    outputBox.innerHTML = "//Copy and paste this code to definitions.h<br />"
      + "//Plugin ID generated by MakeID.HTA (randomly generated)<br />"
      + "#define PLUGIN_ID " + numToHex(Math.floor(Math.random() * 0xFFFFFFFF));
  };
};
//]]>
</script>
<style type="text/css">
body {
  background-color: #eeeeee;   /* possible values: ButtonFace, Menu, threeDFace */
  font: message-box;          /* possible values: menu, message-box, caption */
}

div {
  margin-top: 10px;
}

div#outputbox {
  border: 1px solid black;
  background-color: white;
  font-family: consolas, monospace;
  padding: 5px;
}
</style>
</head>
<body>
<div id="inputboxes">
Enter plugin name: <input id="pluginNameInput" size="50" value="General Plugin Template Project" />
</div>

<div id="outputbox">//Click one of the buttons below...</div>

<div id="buttonbox">
  <input type="button" value="Use Plugin Name to Make ID" id="btnUseCrc32" /> <input type="button" value="Make a Random ID" id="btnUseRandom" />
</div>

<div id="infobox">
Note: This program uses a slightly modified CRC32 algorithm to generate a plugin ID.
</div>

</body>
</html>
